var isValid = function (s) {
    if (s.length % 2 == 1) return false
    var stack = []
    for (let i = 0; i < s.length; i++) {
        const v = s[i]
        if (
            v === '(' ||
            v === '{' ||
            v === '['
        ) {
            stack.push(v)
        } else {
            const t = stack[stack.length - 1]
            if (
                t === '(' && v === ')' ||
                t === '{' && v === '}' ||
                t === '[' && v === ']'
            ) {
                stack.pop()
            } else {
                return false
            }
        }
    }
    return stack.length == 0
};

console.log(isValid('{){)'))
console.log(isValid('({([])})'))
console.log(isValid('({([])}{})}'))